package com.zhengshang.web.controller.app;

import java.util.List;

import com.zhengshang.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.api.domain.AppVideoDrama;
import com.zhengshang.api.service.IAppVideoDramaService;
import com.zhengshang.common.utils.poi.ExcelUtil;
import com.zhengshang.common.core.page.TableDataInfo;

/**
 * 电视剧剧集Controller
 * 
 * @author zhengshang
 * @date 2021-05-17
 */
@RestController
@RequestMapping("/app/drama")
public class AppVideoDramaController extends BaseController
{
    @Autowired
    private IAppVideoDramaService appVideoDramaService;

    /**
     * 查询电视剧剧集列表
     */
    @PreAuthorize("@ss.hasPermi('app:drama:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppVideoDrama appVideoDrama)
    {
        startPage();
        List<AppVideoDrama> list = appVideoDramaService.selectAppVideoDramaList(appVideoDrama);
        return getDataTable(list);
    }

    /**
     * 导出电视剧剧集列表
     */
    @PreAuthorize("@ss.hasPermi('app:drama:export')")
    @Log(title = "电视剧剧集", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppVideoDrama appVideoDrama)
    {
        List<AppVideoDrama> list = appVideoDramaService.selectAppVideoDramaList(appVideoDrama);
        ExcelUtil<AppVideoDrama> util = new ExcelUtil<AppVideoDrama>(AppVideoDrama.class);
        return util.exportExcel(list, "drama");
    }

    /**
     * 获取电视剧剧集详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:drama:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appVideoDramaService.selectAppVideoDramaById(id));
    }

    /**
     * 新增电视剧剧集
     */
    @PreAuthorize("@ss.hasPermi('app:drama:add')")
    @Log(title = "电视剧剧集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppVideoDrama appVideoDrama)
    {
        return toAjax(appVideoDramaService.insertAppVideoDrama(appVideoDrama));
    }

    /**
     * 修改电视剧剧集
     */
    @PreAuthorize("@ss.hasPermi('app:drama:edit')")
    @Log(title = "电视剧剧集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppVideoDrama appVideoDrama)
    {
        appVideoDrama.setCreateBy(SecurityUtils.getUsername());
        return toAjax(appVideoDramaService.updateAppVideoDrama(appVideoDrama));
    }

    /**
     * 删除电视剧剧集
     */
    @PreAuthorize("@ss.hasPermi('app:drama:remove')")
    @Log(title = "电视剧剧集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appVideoDramaService.deleteAppVideoDramaByIds(ids));
    }
}
